class Solution(object):
    def maxLength(self, arr):
        now = {''}
        for s in arr:
            if len(set(s)) == len(s):
                next_set = {s}
                for node in now:
                    next_set.add(node)
                    new_node = node + s
                    if not set(node) & set(s):
                        next_set.add(new_node)
                now = next_set
        max_len = 0
        for s in now:
            max_len = max(max_len, len(s))
        return max_len

data = Solution()
arr = ["un", "iq", "ue"]
print(data.maxLength(arr))
